<?php

	//返回json字符串
	function json($msg = "", $success = false, $data = null){
		$json['msg'] = $msg;
		$json['success'] = $success ? true : false;
		$json['data'] = $data;	
		return json_encode($json, JSON_UNESCAPED_UNICODE);
	}

	//生成随机字符串
	function random_str($length){
		$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
		$randomStr = '';
		for($i = 0; $i < $length; $i++) {
			$randomStr .= $chars[mt_rand(0, strlen($chars) - 1)];
		}
		return $randomStr;
	}

	// 前台地址
	function web_url($path){
		return site_url($path);
	}

	// 后台地址
	function admin_url($path) {
		return site_url(ADMIN_DIR. '/' . $path);
	}

	// 班牌手机端地址
	function wx_url($path) {
		return site_url(WX_DIR . '/' . $path);
	}

	// 官网地址
	function home_url($path) {
		return site_url('home' . '/' . $path);
	}

	// 官网管理后台地址
	function home_admin_url($path) {
		return site_url('web' . '/' . $path);
	}

	// 返回后台数据结构
	function admin_table_data($dataTotal, $data){
		$tableSource['recordsTotal'] = $tableSource['recordsFiltered'] = $dataTotal;
		$tableSource['data'] = $data;

		return json_encode($tableSource);
	}

	// 把一个数组的值变成这个数组的索引
	// arrayValueIndex 如果有逗号，则是两个字段的值拼接
	function array_value_to_key($array, $arrayValueIndex){
		$resultArray = array();
		foreach($array as $item) {
			// 根据拼接后的字符串，来获取数组的值
			$keyIndexStr = "";
			$indexArray = explode(",", $arrayValueIndex);
			foreach($indexArray as $index) $keyIndexStr .= $item[$index];
			// 如果下标是数字格式，转换为数字（加这个会出现0开头的字符串，0被去掉了）
			// if(is_numeric($keyIndexStr)) {
			// 	$keyIndexStr = intval($keyIndexStr);
			// }
			// 将数组的值转换成新的索引
			$resultArray[$keyIndexStr] = $item;
		}	
		return $resultArray;
	}

	// 把一个数组的值变成这个数组的索引
	// arrayValueIndex 如果有逗号，则是两个字段的值拼接（用下划线隔开）
	function array_value_to_key_with_underline($array, $arrayValueIndex){
		$resultArray = array();
		foreach($array as $item) {
			// 根据拼接后的字符串，来获取数组的值
			$keyIndexStr = "";
			$keyIndexArr = array();
			$indexArray = explode(",", $arrayValueIndex);
			foreach($indexArray as $index) {
				array_push($keyIndexArr, $item[$index]);
			}
			$keyIndexStr = implode('_', $keyIndexArr);
			// 将数组的值转换成新的索引
			$resultArray[$keyIndexStr] = $item;
		}	
		return $resultArray;
	}

	// 把二维数组的某个值单独取出来，用逗号隔开
	function array_value_implode($array, $key, $implodeStr = ","){
		$resultArray = array();
		foreach($array as $item) $resultArray[] = $item[$key];
		$resultStr = implode($implodeStr, $resultArray);
		// 若为空，空字符串sql报错，故赋空值
		if(empty($resultStr)) {
			$resultStr = '0';
		}
		return $resultStr;
	}

	// 判断某个日期是星期几，比如‘2019-01-01’
	function date_to_week($date){
		$weekArr = array('周日', '周一', '周二', '周三', '周四', '周五', '周六');
        $timestamp = strtotime($date); 
        return $weekArr[date('w', $timestamp)];
	}

	// 判断某个日期是星期几，比如‘2019-01-01’
	function date_to_week_format_new($date){
		$weekArr = array('星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六');
		$timestamp = strtotime($date); 
		return $weekArr[date('w', $timestamp)];
	}

	// 计算某段时间内的时长，比如 11:00-11:30,时长30分钟
	function get_duration($begin, $end){
		$arrBegin = explode(':', $begin);
		$hourBegin = (int) $arrBegin[0];
		$minBegin = (int) $arrBegin[1];
		$arrEnd = explode(':', $end);
		$hourEnd = (int) $arrEnd[0];
		$minEnd = (int) $arrEnd[1];
		if($hourBegin > $hourEnd){
			return 0;
		}
		if($hourBegin === $hourEnd){
			if($minBegin >= $minEnd){
				return 0;
			}
			return $minEnd - $minBegin;
		}
		$hourGap = $hourEnd - $hourBegin;
		$minGap = $minEnd - $minBegin;
		return 60 * $hourGap + $minGap;
	}

	// 转换考试类型为中文
	function transform_type($type, $lessonName, $bothHave){
		switch($type){		
			case 'selfStudy':
				return '自习';
			case 'majorExam':
			case 'custom':
				return $lessonName;
			case 'chosenExam':
				if($bothHave) {
					return $lessonName . ' - 等级考';
				} else {
					return $lessonName;
				}
			case 'studyExam':
				if($bothHave) {
					return $lessonName . ' - 合格考';
				} else {
					return $lessonName;
				}
			default: 
				return '';
		}
	}

	// 转换时段为中文
	function transform_part_of_day($partOfDay){
		if($partOfDay === 'morning'){
			$res = '上午';
		} else if($partOfDay === 'afternoon') {
			$res = '下午';
		} else {
			$res = '晚上';
		}
		return $res;
	}

	// 转换资源格式名
	function transform_source_format($title){
		switch($title){
			case SOURCE_FORMAT_VIDEO:
				return '视频';
				break;
			case SOURCE_FORMAT_AUDIO:
				return '音频';
				break;
			case SOURCE_FORMAT_IMAGE_TEXT:
				return '图文';
				break;
			case SOURCE_FORMAT_OTHER:
				return '其他格式';
				break;
			default:
				return '';
		}
	}

	// 转换资源状态
	function transform_source_state($state){
		switch($state){
			case SOURCE_PENDING:
				return '<span class="label label-warning">未审核</span>';
				break;
			case SOURCE_ACCEPTED:
				return '<span class="label label-success">已通过</span>';
				break;
			case SOURCE_REJECTED:
				return '<span class="label label-danger">已拒绝</span>';
				break;
			default:
				return '';
		}
	}

	// 转换考试类型为中文
	function transform_exam_type_to_chinese($type) {
		switch($type){
			case EXAM_TYPE_CHOSEN:
				return '等级考';
				break;
			case EXAM_TYPE_MAJOR:
				return '必考';
				break;
			case EXAM_TYPE_CUSTOM:
				return '自定义';
				break;
			case EXAM_TYPE_STUDY:
				return '合格考';
				break;
			case EXAM_TYPE_SELF:
				return '自习';
				break;
			default:
				return '';
		}
	}

	// 根据考试开始时间，计算时段,参数格式‘09:00’
	function get_part_of_day($time) {
		$arr = explode(':', $time);
		$hour = (int) $arr[0];
		if($hour < 12) {
			return 'morning';
		} elseif($hour < 18) {
			return 'afternoon';
		} else {
			return 'evening';
		}
	}

	// 某时间点后移多少分钟，格式‘09:00’
	function add_time($time, $offset) {
		$timeArr = explode(':', $time);
		$hour = $timeArr[0];
		$min = $timeArr[1];
		$count = $min + $offset;
		$minNew = $count % 60;
		$hourNew = (int) $hour + floor($count / 60); 
		if($minNew < 10) {
			$minNew = '0' . $minNew;
		}
		if($hourNew == 25) {
			$hourNew = 1;
		}
		if($hourNew < 10) {
			$hourNew = '0' . $hourNew;
		}
		return $hourNew . ':' . $minNew;
	}
	// 某时间点前移多少分钟，格式‘09:00’
	function subtract_time($time, $offset) {
		$timeArr = explode(':', $time);
		$hour = $timeArr[0];
		$min = $timeArr[1];
		// 总共多少分钟
		$minCount = $hour * 60 + $min;
		$minCountNew = $minCount - $offset;
		if($minCountNew <= 0) {
			return "00:00";
		}
		$hourNew = floor($minCountNew / 60);
		$minNew = $minCountNew % 60;
		if($minNew < 10) {
			$minNew = '0' . $minNew;
		}
		if($hourNew < 10) {
			$hourNew = '0' . $hourNew;
		}
		return $hourNew . ':' . $minNew;
	}

	// phpexcel中设置excel第一列的坐标
	function excelSheetIndex() {
		return array(
			'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
			'AA','AB','AC','AD','AE','AF','AG','AH','AI','AJ','AK','AL','AM','AN','AO','AP','AQ','AR','AS','AT','AU','AV','AW','AX','AY','AZ',
			'BA','BB','BC','BD','BE','BF','BG','BH','BI','BJ','BK','BL','BM','BN','BO','BP','BQ','BR','BS','BT','BU','BV','BW','BX','BY','BZ',
			'CA','CB','CC','CD','CE','CF','CG','CH','CI','CJ','CK','CL','CM','CN','CO','CP','CQ','CR','CS','CT','CU','CV','CW','CX','CY','CZ',
			'DA','DB','DC','DD','DE','DF','DG','DH','DI','DJ','DK','DL','DM','DN','DO','DP','DQ','DR','DS','DT','DU','DV','DW','DX','DY','DZ',
			'EA','EB','EC','ED','EE','EF','EG','EH','EI','EJ','EK','EL','EM','EN','EO','EP','EQ','ER','ES','ET','EU','EV','EW','EX','EY','EZ',
		);
	}

	/**
	 * execl数据导出课表
	 * @param string $title 模型名
	 * @param array $cellName 表头及字段名
	 * @param array $data 导出的表数据
	 * @param array $mergeLocations 合并的单元格，如'A1:G1'
	 *
	 * 特殊处理：合并单元格需要先对数据进行处理
	 */
	function exportScheduleExcel($filename, $data, $mergeLocations)
	{    
		$CI =& get_instance();
		$CI->load->library('PHPExcel');
		$objPHPExcel = new PHPExcel();
		// 设置文件属性
		$objPHPExcel->getProperties()
			->setCreator("yzh")  
			->setLastModifiedBy("yzh")  
			->setTitle("Office 2007 XLSX Test Document")  
			->setSubject("Office 2007 XLSX Test Document")  
			->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")  
			->setKeywords("office 2007 openxml php")  
			->setCategory("schedule export file");  
		// 设置标题  
		$objPHPExcel->getActiveSheet()->setTitle($filename);
		//设置样式：  
		$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(20);  //列宽必须单个设置
		$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(12);  //列宽必须单个设置
		$activeSheet = $objPHPExcel->setActiveSheetIndex(0);
		// excel坐标
		$excelSheetArr = excelSheetIndex();
		// 总行数
		$rowCount = count($data);
		// 总列数
		$colCount = count($data[3]);
		// 最后一列坐标
		$colEnd = $excelSheetArr[$colCount - 1];
		// 设置字体水平和垂直居中
		$objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
		// 设置边框
		$styleBorder = array(
			'borders' => array(
				'allborders' => array( 									//设置全部边框
					'style' => \PHPExcel_Style_Border::BORDER_THIN 		// 粗的是thick
				)
			)
		);
		$objPHPExcel->getActiveSheet()->getStyle( 'A1:' . $colEnd . $rowCount)->applyFromArray($styleBorder);
		// 合并第一行
		$objPHPExcel->getActiveSheet()->mergeCells('A1:' . $colEnd . '1');
		// 合并‘年级’，‘班级’，‘班主任’项
		$objPHPExcel->getActiveSheet()->mergeCells('A2:A4');
		$objPHPExcel->getActiveSheet()->mergeCells('B2:B4');
		$objPHPExcel->getActiveSheet()->mergeCells('C2:C4');
		// 合并传过来的参数
		foreach($mergeLocations as $location) {
			$objPHPExcel->getActiveSheet()->mergeCells($location);
		}
		// 赋值
		foreach($data as $key => $value) {
			foreach($value as $keyChild => $valueChild) {
				$index = $key + 1;
				$activeSheet->setCellValue($excelSheetArr[$keyChild] . $index, $valueChild);
			}
		}

		// 处理IE或edge浏览器文件名乱码
		$filename = iconv('UTF-8', 'GBK//IGNORE', $filename);
		header('Content-Type: application/vnd.ms-excel');  
		header('Content-Disposition: attachment;filename="'. $filename .'.xls"');  
		header('Cache-Control: max-age=0');
		
		// $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
		$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
		$objWriter->save('php://output');  
		exit;  
	}

	/**
	 * execl数据导出--健康
	 * @param string $title 模型名
	 * @param array $cellName 表头及字段名
	 * @param array $data 导出的表数据
	 * @param array $mergeLocations 合并的单元格，如'A1:G1'
	 *
	 * 特殊处理：合并单元格需要先对数据进行处理
	 */
	function exportHealthExcel($filename, $data)
	{    
		$CI =& get_instance();
		$CI->load->library('PHPExcel');
		$objPHPExcel = new PHPExcel();
		// 设置文件属性
		$objPHPExcel->getProperties()
			->setCreator("yzh")  
			->setLastModifiedBy("yzh")  
			->setTitle("Office 2007 XLSX Test Document")  
			->setSubject("Office 2007 XLSX Test Document")  
			->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")  
			->setKeywords("office 2007 openxml php")  
			->setCategory("schedule export file");  
		// 设置标题  
		$objPHPExcel->getActiveSheet()->setTitle($filename);
		//设置样式：  
		$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(6);  //列宽必须单个设置
		$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(10);  //列宽必须单个设置
		$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(8);  //列宽必须单个设置
		$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(24);  //列宽必须单个设置
		$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(16);  //列宽必须单个设置
		$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(16);  //列宽必须单个设置
		$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(26);  //列宽必须单个设置
		$objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(20);  //列宽必须单个设置
		$objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(16);  //列宽必须单个设置
		$objPHPExcel->getActiveSheet()->getColumnDimension('J')->setWidth(18);  //列宽必须单个设置
		$objPHPExcel->getActiveSheet()->getColumnDimension('k')->setWidth(18);  //列宽必须单个设置
		$objPHPExcel->getActiveSheet()->getColumnDimension('L')->setWidth(24);  //列宽必须单个设置
		$objPHPExcel->getActiveSheet()->getColumnDimension('M')->setWidth(8);  //列宽必须单个设置
		$objPHPExcel->getActiveSheet()->getColumnDimension('N')->setWidth(12);  //列宽必须单个设置
		$objPHPExcel->getActiveSheet()->getColumnDimension('O')->setWidth(22);  //列宽必须单个设置

		$activeSheet = $objPHPExcel->setActiveSheetIndex(0);
		// excel坐标
		$excelSheetArr = excelSheetIndex();
		// 总行数
		$rowCount = count($data);
		// 总列数
		$colCount = count($data[0]);
		// 最后一列坐标
		$colEnd = $excelSheetArr[$colCount - 1];
		// 设置字体水平和垂直居中
		$objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
		// 设置边框
		$styleBorder = array(
			'borders' => array(
				'allborders' => array( 									//设置全部边框
					'style' => \PHPExcel_Style_Border::BORDER_THIN 		// 粗的是thick
				)
			)
		);
		$objPHPExcel->getActiveSheet()->getStyle( 'A1:' . $colEnd . $rowCount)->applyFromArray($styleBorder);
		// 赋值
		foreach($data as $key => $value) {
			foreach($value as $keyChild => $valueChild) {
				$index = $key + 1;
				$activeSheet->setCellValue($excelSheetArr[$keyChild] . $index, $valueChild);
			}
		}
		// 处理IE或edge浏览器文件名乱码
		$filename = iconv('UTF-8', 'GBK//IGNORE', $filename);
		header('Content-Type: application/vnd.ms-excel');  
		header('Content-Disposition: attachment;filename="'. $filename .'.xls"');  
		header('Cache-Control: max-age=0');
		// $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
		$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
		$objWriter->save('php://output');  
		exit;  
	}

	// execl数据导出--通用
    function exportExcel($filename, $data, $widthParams = array())
	{    
		$CI =& get_instance();
		$CI->load->library('PHPExcel');
		$objPHPExcel = new PHPExcel();
		// 设置文件属性
		$objPHPExcel->getProperties()
			->setCreator("yzh")  
			->setLastModifiedBy("yzh")  
			->setTitle("Office 2007 XLSX Test Document")  
			->setSubject("Office 2007 XLSX Test Document")  
			->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")  
			->setKeywords("office 2007 openxml php")  
			->setCategory("schedule export file");  
		// 设置标题  
		$objPHPExcel->getActiveSheet()->setTitle($filename);
		// 设置列宽
		foreach($widthParams as $params) {
			$objPHPExcel->getActiveSheet()->getColumnDimension($params['index'])->setWidth($params['width']);  //列宽必须单个设置
		}

		$activeSheet = $objPHPExcel->setActiveSheetIndex(0);
		// excel坐标
		$excelSheetArr = excelSheetIndex();
		// 总行数
		$rowCount = count($data);
		// 总列数
		$colCount = count($data[0]);
		// 最后一列坐标
		$colEnd = $excelSheetArr[$colCount - 1];
		// 设置字体水平和垂直居中
		$objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
		// 设置边框
		$styleBorder = array(
			'borders' => array(
				'allborders' => array( 									//设置全部边框
					'style' => \PHPExcel_Style_Border::BORDER_THIN 		// 粗的是thick
				)
			)
		);
		$objPHPExcel->getActiveSheet()->getStyle( 'A1:' . $colEnd . $rowCount)->applyFromArray($styleBorder);
		// 赋值
		foreach($data as $key => $value) {
			foreach($value as $keyChild => $valueChild) {
				$index = $key + 1;
				$activeSheet->setCellValue($excelSheetArr[$keyChild] . $index, $valueChild);
			}
		}
		// 处理IE或edge浏览器文件名乱码
		$filename = iconv('UTF-8', 'GBK//IGNORE', $filename);
		header('Content-Type: application/vnd.ms-excel');  
		header('Content-Disposition: attachment;filename="'. $filename .'.xls"');  
		header('Cache-Control: max-age=0');
		// $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
		$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
		// ob_end_clean();
		$objWriter->save('php://output');  
		exit;  
	}

	// 导入课表时初始时间数组,参数为每天课程节数,目前最大为14节
	function get_default_schedule_time_arr($dayNum){
		$timeArr = array(
			array(
				'timeslotInDay' => 1,
				'beginTime' => '08:00',
				'duration' => 45,
				'breakDuration' => 10,
			),
			array(
				'timeslotInDay' => 2,
				'beginTime' => "08:55",
				'duration' => 1,
				'breakDuration' => 1,
			)
		);
		if($dayNum > 2) {
			array_push($timeArr, array('timeslotInDay' => 3, 'beginTime' => "09:50", 'duration' => 45, 'breakDuration' => 10));
			if($dayNum > 3) {
				array_push($timeArr, array('timeslotInDay' => 4, 'beginTime' => "10:45", 'duration' => 45, 'breakDuration' => 10));
				if($dayNum > 4) {
					array_push($timeArr, array('timeslotInDay' => 5, 'beginTime' => "14:00", 'duration' => 45, 'breakDuration' => 10));
					if($dayNum > 5) {
						array_push($timeArr, array('timeslotInDay' => 6, 'beginTime' => "14:55", 'duration' => 45, 'breakDuration' => 10));
						if($dayNum > 6) {
							array_push($timeArr, array('timeslotInDay' => 7, 'beginTime' => "15:50", 'duration' => 45, 'breakDuration' => 10));
							if($dayNum > 7) {
								array_push($timeArr, array('timeslotInDay' => 8, 'beginTime' => "16:45", 'duration' => 45, 'breakDuration' => 10));
								if($dayNum > 8) {
									array_push($timeArr, array('timeslotInDay' => 9, 'beginTime' => "17:40", 'duration' => 45, 'breakDuration' => 10));
									if($dayNum > 9) {
										array_push($timeArr, array('timeslotInDay' => 10, 'beginTime' => "19:30", 'duration' => 45, 'breakDuration' => 10));
										if($dayNum > 10) {
											array_push($timeArr, array('timeslotInDay' => 11, 'beginTime' => "20:25", 'duration' => 45, 'breakDuration' => 10));
											if($dayNum > 11) {
												array_push($timeArr, array('timeslotInDay' => 12, 'beginTime' => "21:20", 'duration' => 45, 'breakDuration' => 10));
												if($dayNum > 12) {
													array_push($timeArr, array('timeslotInDay' => 13, 'beginTime' => "22:15", 'duration' => 45, 'breakDuration' => 10));
													if($dayNum > 13) {
														array_push($timeArr, array('timeslotInDay' => 14, 'beginTime' => "23:10", 'duration' => 45, 'breakDuration' => 10));
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
		return $timeArr;
	}

	// 获取班牌所有主题
	function get_all_brand_themes() {
		return array(
			array(
				'name' => BRAND_THEME_BLUE,
				'chineseName' => transform_brand_them(BRAND_THEME_BLUE)
			),
			array(
				'name' => BRAND_THEME_YELLOW,
				'chineseName' => transform_brand_them(BRAND_THEME_YELLOW)
			)
		);
	}

	// 获取班牌主题中文
	function transform_brand_them($theme) {
		switch($theme){
			case BRAND_THEME_BLUE:
				return '蓝色';
			case BRAND_THEME_YELLOW:
				return '橙色';
			default: 
				return '';
		}
	}

	// 获取人脸识别模块
	function get_all_face_detect() {
		return array(
			array(
				'value' => FACE_DETECT_CLOSE,
				'title' => transform_face_detect(FACE_DETECT_CLOSE)
			),
			array(
				'value' => FACE_DETECT_OPEN,
				'title' => transform_face_detect(FACE_DETECT_OPEN)
			),
			array(
				'value' => FACE_DETECT_TEMPERATURE,
				'title' => transform_face_detect(FACE_DETECT_TEMPERATURE)
			),
			array(
				'value' => FACE_DETECT_TEMPERATURE_HEAD,
				'title' => transform_face_detect(FACE_DETECT_TEMPERATURE_HEAD)
			),
			array(
				'value' => FACE_DETECT_TEMPERATURE_WRIST,
				'title' => transform_face_detect(FACE_DETECT_TEMPERATURE_WRIST)
			),
		);
	}

	// 转换人脸识别名称
	function transform_face_detect($face) {
		switch($face){
			case FACE_DETECT_CLOSE:
				return '关闭';
			case FACE_DETECT_OPEN:
				return '人脸识别';
			case FACE_DETECT_TEMPERATURE:
				return '热成像测温';
			case FACE_DETECT_TEMPERATURE_HEAD:
				return '额温枪测温';
			case FACE_DETECT_TEMPERATURE_WRIST:
				return '腕温测温';
			default: 
				return '';
		}
	}

	// 获取班牌主题颜色css
	function get_brand_theme_style($theme) {
		switch($theme){
			case BRAND_THEME_BLUE:
				return '<span style="color:#337ab7;">&nbsp;&nbsp;&nbsp;&nbsp;蓝色</span>';
			case BRAND_THEME_YELLOW:
				return '<span style="color:#FF9900">&nbsp;&nbsp;&nbsp;&nbsp;橙色</span>';
			default: 
				return '';
		}
	}

	// 用于定时开关机
	// 转换‘周几’为中文，周日-周六 => 1-7
	function transform_week_to_chinese($weekday) {
		switch($weekday){
			case 1:
				return '周日';
			case 2:
				return '周一';
			case 3:
				return '周二';
			case 4:
				return '周三';
			case 5:
				return '周四';
			case 6:
				return '周五';
			case 7:
				return '周六';
			default:
				return '';
		}
	}

	function transform_week_to_chinese_long($weekday) {
		switch($weekday){
			case 1:
				return '星期日';
			case 2:
				return '星期一';
			case 3:
				return '星期二';
			case 4:
				return '星期三';
			case 5:
				return '星期四';
			case 6:
				return '星期五';
			case 7:
				return '星期六';
			default:
				return '';
		}
	}

	// 去除A标签
	function trim_link_tags($content){
		$result = preg_replace("#<a[^>]*>(.*?)</a>#is", "$1", $content);
		return $result;
	}

	//判断远程文件
	function check_remote_file_exists($url) {
		$curl = curl_init($url);
		// 不取回数据
		curl_setopt($curl, CURLOPT_NOBODY, true);
		// 发送请求
		$result = curl_exec($curl);
		$found = false;
		// 如果请求没有发送失败
		if ($result !== false) {
			// 再检查http响应码是否为200
			$statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
			if ($statusCode == 200) $found = true;
		}
		curl_close($curl);
		return $found;
	}

	// 获取开始日期与结束日期之间所有日期
	function getDateFromRange($startdate, $enddate){
		$stimestamp = strtotime($startdate);
		$etimestamp = strtotime($enddate);
		// 计算日期段内有多少天
		$days = ($etimestamp-$stimestamp)/86400 + 1;
		// 保存每天日期
		$date = array();
		for($i=0; $i<$days; $i++){
			$date[] = date('Y-m-d', $stimestamp + (86400 * $i));
		}
		return $date;
	}

	// 时间去掉秒，2010-10-10 12:12:12 -> 2010-10-10 12:12
	function time_remove_second($time) {
		$arr = explode(':', $time);
		array_pop($arr);
		return implode(':', $arr);
	}

	// 获取中文的首字母
	function getFirstChar($s) {  
		$s0 = mb_substr($s,0,1,'utf-8'); //获取名字的姓
		$s = iconv('UTF-8','GBK', $s0); //将UTF-8转换成GB2312编码  
		if(ord($s0)>128) {//汉字开头，汉字没有以U、V开头的  
		$asc = ord($s{0}) * 256 + ord($s{1}) - 65536;  
			if($asc>=-20319 and $asc<=-20284)return "A";  
			if($asc>=-20283 and $asc<=-19776)return "B";  
			if($asc>=-19775 and $asc<=-19219)return "C";  
			if($asc>=-19218 and $asc<=-18711)return "D";  
			if($asc>=-18710 and $asc<=-18527)return "E";  
			if($asc>=-18526 and $asc<=-18240)return "F";  
			if($asc>=-18239 and $asc<=-17760)return "G";  
			if($asc>=-17759 and $asc<=-17248)return "H";  
			if($asc>=-17247 and $asc<=-17418)return "I";              
			if($asc>=-17417 and $asc<=-16475)return "J";               
			if($asc>=-16474 and $asc<=-16213)return "K";               
			if($asc>=-16212 and $asc<=-15641)return "L";               
			if($asc>=-15640 and $asc<=-15166)return "M";               
			if($asc>=-15165 and $asc<=-14923)return "N";               
			if($asc>=-14922 and $asc<=-14915)return "O";               
			if($asc>=-14914 and $asc<=-14631)return "P";               
			if($asc>=-14630 and $asc<=-14150)return "Q";               
			if($asc>=-14149 and $asc<=-14091)return "R";               
			if($asc>=-14090 and $asc<=-13319)return "S";               
			if($asc>=-13318 and $asc<=-12839)return "T";               
			if($asc>=-12838 and $asc<=-12557)return "W";               
			if($asc>=-12556 and $asc<=-11848)return "X";               
			if($asc>=-11847 and $asc<=-11056)return "Y";               
			if($asc>=-11055 and $asc<=-10247)return "Z";   
		} elseif(ord($s)>=48 and ord($s)<=57) {//数字开头  
			switch(iconv_substr($s,0,1,'utf-8')) {  
				case 1:return "Y";  
				case 2:return "E";  
				case 3:return "S";  
				case 4:return "S";  
				case 5:return "W";  
				case 6:return "L";  
				case 7:return "Q";  
				case 8:return "B";  
				case 9:return "J";  
				case 0:return "L";  
			}                 
		} else if(ord($s)>=65 and ord($s)<=90) {//大写英文开头  
			return substr($s,0,1);  
		} else if(ord($s)>=97 and ord($s)<=122) {//小写英文开头  
			return strtoupper(substr($s,0,1));  
		} else {  
			return iconv_substr($s0,0,1,'utf-8');//中英混合的词语提取首个字符即可       
		}  
	}

	// 留言内容转换<br>格式
	function transformBrForNote($content) {
		if(strstr($content, '<br>')) {
			$arr = explode('<br>', $content);
			return $arr[0] . '...';
		} else {
			return $content;
		}
	}

	// 获取健康相关数据项
	function get_health_const_data() {
        // 目前状态
        $currentStatus = array(
            0 => '健康',
            1 => '居家医学观察',
            2 => '集中医学观察',
		);
		// 家属状态
        $familyStatus = array(
            0 => '健康',
            1 => '居家医学观察',
            2 => '集中医学观察',
		);
		// 症状
        $symptom = array(
            0 => '自觉正常',
            1 => '发热',
            2 => '干咳',
            3 => '乏力',
            4 => '腹泻',
            5 => '感冒',
			6 => '头疼头晕',
			7 => '其他'
		);
		// 诊疗情况
        $treatment = array(
            0 => '自我观察',
            1 => '已去定点医院检查无问题',
            2 => '已去定点医院检查未出结果',
            3 => '以确诊为新型冠状病毒感染'
		);
		return array(
			'current_status' => $currentStatus,
			'family_status' => $familyStatus,
			'symptom' => $symptom,
			'treatment' => $treatment,
		);
	}

	// 获取健康预警相关数据项
	function get_health_warn_const_data() {
        // 目前状态
        $currentStatus = array(
            0 => '健康',
            1 => '居家医学观察',
            2 => '集中医学观察',
		);
		// 家属状态
        $familyStatus = array(
            0 => '健康',
            1 => '居家医学观察',
            2 => '集中医学观察',
		);
		// 症状
        $symptom = array(
            0 => '自觉正常',
            1 => '发热',
            2 => '干咳',
            3 => '乏力',
            4 => '腹泻',
            5 => '感冒',
			6 => '头疼头晕',
			7 => '其他'
		);
		// 是否往返武汉
		$isReturn = array(
			0 => '否',
			1 => '是'
		);
		// 是否有密切接触
		$isContact = array(
			0 => '否',
			1 => '是'
		);
		// 是否滞留湖北地区
		$isDetained = array(
			0 => '否',
			1 => '是'
		);
		return array(
			'current_status' => $currentStatus,
			'family_status' => $familyStatus,
			'symptom' => $symptom,
			'is_return' => $isReturn,
			'is_contact' => $isContact,
			'is_detained' => $isDetained
		);
	}

	// 获取健康预警字段列表
	function get_health_warn_key_const_data() {
		return array(
			'current_status' => '目前状态',
			'family_status' => '家属状态',
			'symptom' => '出现的症状',
			'is_return' => '是否往返武汉及毗邻地区',
			'is_contact' => '是否与疫情高发地人员有密切接触',
			'is_detained' => '是否滞留在湖北地区'
		);
	}

	// 获取德育活动审核状态中文格式
	function transform_activity_state_to_chinese($state) {
		switch($state){		
			case MORAL_ACCEPTED:
				return '已通过';
			case MORAL_REJECTED:
				return '未通过';
			case MORAL_PENDING:
				return '未审核';
			default: 
				return '';
		}
	}

	// 转换德育活动审核状态
	function transform_activity_state($state){
		switch($state){
			case MORAL_PENDING:
				return '<span class="" style="color:#FD7D00">未审核</span>';
				break;
			case MORAL_ACCEPTED:
				return '<span class="" style="color:#18D07C">已通过</span>';
				break;
			case MORAL_REJECTED:
				return '<span class="" style="color:#D9534F">不通过</span>';
				break;
			default:
				return '';
		}
	}

	// 转换签到类型
	function transform_sign_type($type) {
		switch($type){
			case SIGN_TYPE_CARD:
				return '刷卡';
			case SIGN_TYPE_FACE:
				return '人脸识别';
			case SIGN_TYPE_TEMPERATURE:
				return '热成像测温';
			case SIGN_TYPE_TEMPERATURE_HEAD:
				return '额温枪测温';
			case SIGN_TYPE_TEMPERATURE_WRIST:
				return '腕温测温';
			case SIGN_TYPE_GATE:
				return '闸机';
			case SIGN_TYPE_AIO:
				return '一体机';
			default:
				return '';
		}
	}

	// 转换签到状态
	function transform_sign_state($state) {
		switch($state){
			case SIGN_STATE_NORMAL:
				return '行政班考勤';
			case SIGN_STATE_NORMAL_SUPPLEMENT:
				return '行政班补签';
			case SIGN_STATE_TEACH:
				return '教学班考勤';
			case SIGN_STATE_TEACH_SUPPLEMENT:
				return '教学班补签';
			case SIGN_STATE_EXAM:
				return '考试签到';
			case SIGN_STATE_EXAM_SUPPLEMENT:
				return '考试补签';
			case SIGN_STATE_LEAVE:
				return '离校考勤';
			case SIGN_STATE_ELECTIVE:
				return '选修班考勤';
			case SIGN_STATE_ELECTIVE_SUPPLEMENT:
				return '选修班补签';
			case SIGN_STATE_GATE_EXIT:
				return '闸机出口考勤';
			case SIGN_STATE_GATE_ENTRY:
				return '闸机入口考勤';
			case SIGN_STATE_AIO:
				return '一体机考勤';
			case SIGN_STATE_AIO_SUPPLEMENT:
				return '一体机补签';
			default: 
				return '';
		}
	}

	// 转换闸机用户身份类型
	function transform_gate_user_type($type) {
		switch($type){
			case GATE_USER_TYPE_TEACHER:
				return '<span style="color:#FD7D00">老师</span>';
			case GATE_USER_TYPE_STUDENT:
				return '<span class="text-primary">学生</span>';
			case GATE_USER_TYPE_PARENT:
				return '<span class="text-success">家长</span>';
			default: 
				return '';
		}
	}

	// 转换闸机任务类型
	function transform_gate_task_type($type) {
		switch($type){
			case GATE_TASK_TYPE_ADD:
				return '<span class="text-primary">新增</span>';
			case GATE_TASK_TYPE_UPDATE:
				return '<span style="color:#FD7D00">修改</span>';
			case GATE_TASK_TYPE_DELETE:
				return '<span class="text-danger">删除</span>';
			default: 
				return '';
		}
	}

	// 转换闸机任务状态
	function transform_gate_task_state($state) {
		switch($state){
			case GATE_TASK_STATE_NEW:
				return '<span class="text-primary">待处理</span>';
			case GATE_TASK_STATE_OK:
				return '<span class="text-success">完成</span>';
			case GATE_TASK_STATE_FAIL:
				return '<span class="text-danger">失败</span>';
			default: 
				return '';
		}
	}

	// 转换一体机用户身份类型
	function transform_aio_user_type($type) {
		switch($type){
			case AIO_USER_TYPE_TEACHER:
				return '<span style="color:#FD7D00">老师</span>';
			case AIO_USER_TYPE_STUDENT:
				return '<span class="text-primary">学生</span>';
			case AIO_USER_TYPE_PARENT:
				return '<span class="text-success">家长</span>';
			default: 
				return '';
		}
	}

	// 转换一体机任务类型
	function transform_aio_task_type($type) {
		switch($type){
			case AIO_TASK_TYPE_ADD:
				return '<span class="text-primary">新增</span>';
			case AIO_TASK_TYPE_UPDATE:
				return '<span style="color:#FD7D00">修改</span>';
			case AIO_TASK_TYPE_DELETE:
				return '<span class="text-danger">删除</span>';
			default: 
				return '';
		}
	}

	// 转换一体机任务状态
	function transform_aio_task_state($state) {
		switch($state){
			case AIO_TASK_STATE_NEW:
				return '<span class="text-primary">待处理</span>';
			case AIO_TASK_STATE_OK:
				return '<span class="text-success">完成</span>';
			case AIO_TASK_STATE_FAIL:
				return '<span class="text-danger">失败</span>';
			default: 
				return '';
		}
	}

	// 温度大于等于43度，显示未知
	function handle_temperature($temp) {
		if(!empty($temp) && $temp >= TEMPERATURE_UNKNOWN) {
			return '未知';
		}
		return $temp;
	}

	function get_sys_img($filename) {
		return site_url(APPLICATION_FOLDER. "/views/") . ADMIN_DIR. "/" . "assets/images/" . $filename;
	}

	// 班牌类型
	function transform_brand_type($type) {
		switch($type){
			case BRAND_TYPE_NORMAL:
				return '普通教室';
			case BRAND_TYPE_GRADE:
				return '年级办公室';
			case BRAND_TYPE_PROFESSIONAL:
				return '专业课室';
			case BRAND_TYPE_CANTEEN:
				return '食堂';	
			case BRAND_TYPE_SCHOOL_GATE:
				return '校门';	
			default: 
				return '';
		}
	}

	// 获取本周所有日期，截止当天
	function get_this_week_date($time = ''){
		$time = $time != '' ? $time : time();
		// 获取今天日期
		$today = date('Y-m-d');        
		//获取当前周几，周日得取7，不能取0
		$week = date('w', $time);
		if($week == 0) {
			$week = 7;
		}
		$dateArr = [];
		for ($i=1; $i<=7; $i++){
			$date = date('Y-m-d', strtotime( '+' . $i-$week .' days', $time));
			if($date <= $today ) {
				$dateArr[] = $date;
			}
		}
		return $dateArr;
	}

	// 转换用户身份类型
	function transform_user_type($type) {
		switch($type){
			case USER_TYPE_TEACHER:
				return '<span style="color:#FD7D00">老师</span>';
			case USER_TYPE_STUDENT:
				return '<span class="text-primary">学生</span>';
			default: 
				return '';
		}
	}